package com.zero.qth.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zero.common.core.domain.page.PageDomain;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zero.common.annotation.log.Log;
import com.zero.common.core.basecontroller.BaseController;
import com.zero.common.core.domain.result.AjaxResult;
import com.zero.common.core.enums.BusinessType;
import com.zero.qth.domain.Property;
import com.zero.qth.service.IPropertyService;
import com.zero.common.core.utils.poi.ExcelUtil;
import com.zero.common.core.domain.page.TableDataInfo;

/**
 * 配置表Controller
 * 
 * @author cai-xu-kun
 * @date 2025-09-26
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "配置表")
@RequestMapping("/qth/property")
public class PropertyController extends BaseController {

    private final IPropertyService propertyService;

    /**
     * 查询配置表分页
     */
    @ApiOperation("查询配置表分页")
    @PreAuthorize("@ss.hasPermi('qth:property:list')")
    @GetMapping("/list")
    public TableDataInfo list(Property property) {
        PageDomain pageDomain = this.startPage();
        Page<Property> p = new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize());
        Page<Property> page = propertyService.selectPropertyListPage(property, p);
        return this.getDataTable(page);
    }

    /**
     * 导出配置表列表
     */
    @ApiOperation("导出配置表列表")
    @PreAuthorize("@ss.hasPermi('qth:property:export')")
    @Log(title = "配置表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Property property) {
        List<Property> list = propertyService.selectPropertyList(property);
        ExcelUtil<Property> util = new ExcelUtil<Property>(Property.class);
        util.exportExcel(response, list, "配置表数据");
    }

    /**
     * 获取配置表详细信息
     */
    @ApiOperation("获取配置表详细信息")
    @PreAuthorize("@ss.hasPermi('qth:property:query')")
    @GetMapping(value = "/{theKey}")
    public AjaxResult getInfo(@PathVariable("theKey") String theKey) {
        return success(propertyService.selectPropertyByTheKey(theKey));
    }

    /**
     * 新增配置表
     */
    @ApiOperation("新增配置表")
    @PreAuthorize("@ss.hasPermi('qth:property:add')")
    @Log(title = "配置表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Property property) {
        return toAjax(propertyService.insertProperty(property));
    }

    /**
     * 修改配置表
     */
    @ApiOperation("修改配置表")
    @PreAuthorize("@ss.hasPermi('qth:property:edit')")
    @Log(title = "配置表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Property property) {
        return toAjax(propertyService.updateProperty(property));
    }

    /**
     * 删除配置表
     */
    @ApiOperation("删除配置表")
    @PreAuthorize("@ss.hasPermi('qth:property:remove')")
    @Log(title = "配置表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{theKeys}")
    public AjaxResult remove(@PathVariable String[] theKeys) {
        return toAjax(propertyService.deletePropertyByTheKeys(theKeys));
    }
}
